﻿Public Class fConsecutivo
    Dim daClave As lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter


    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Try
            If Me.DsGlobal.GLO_CONSECUTIVO.GetChanges() IsNot Nothing Then
                GLO_CONSECUTIVOBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    GLO_CONSECUTIVOBindingNavigatorSaveItem.PerformClick()
                End If
            End If
            Me.GlO_CONSECUTIVOTableAdapter1.Fill(DsGlobal.GLO_CONSECUTIVO)

        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub


    Private Sub GLO_CONSECUTIVOBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GLO_CONSECUTIVOBindingNavigatorSaveItem.Click
        Try
            Validate()
            GLO_CONSECUTIVOBindingSource.EndEdit()
            Me.GlO_CONSECUTIVOTableAdapter1.Update(DsGlobal.GLO_CONSECUTIVO)
            MessageBox.Show("Se salvo información de consecutivos con exito", "Salva Consecutivos", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub GLO_CONSECUTIVODataGridView_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles GLO_CONSECUTIVODataGridView.CellBeginEdit

        If e.ColumnIndex = 1 AndAlso GLO_CONSECUTIVODataGridView.Rows(e.RowIndex).Cells(0).Value Is DBNull.Value Then
            Dim dt As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASDataTable
            dt = daClave.GetDataByIdClavePrimaria("GLO_CONSECUTIVO")
            If dt.Count Then
                Dim dr As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASRow
                dr = dt.Rows(0)
                Dim Cons As lbGlobalcom.ConsecTablas = New lbGlobalcom.ConsecTablas(dr("TABLA"), dr("CAMPO"), dr("LONGITUD"))
                GLO_CONSECUTIVODataGridView.Rows(e.RowIndex).Cells(0).Value = Cons.NumeroConsec
                Cons = Nothing
                GLO_CONSECUTIVOBindingSource.EndEdit()
                Me.GlO_CONSECUTIVOTableAdapter1.Update(DsGlobal.GLO_CONSECUTIVO)
            End If
        End If
        
    End Sub

    Private Sub GLO_CONSECUTIVODataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles GLO_CONSECUTIVODataGridView.DataError
        MessageBox.Show(e.Exception.Message)
    End Sub

   
    Private Sub GLO_CONSECUTIVODataGridView_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles GLO_CONSECUTIVODataGridView.UserDeletedRow
        Try
            MessageBox.Show("Se salvarón registros con exito", "Salvar Registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Me.GlO_CONSECUTIVOTableAdapter1.Update(DsGlobal.GLO_CONSECUTIVO)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub GLO_CONSECUTIVODataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles GLO_CONSECUTIVODataGridView.UserDeletingRow
        If MessageBox.Show("Esta seguro que desea eliminar este regsitro", "Eliminar Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub

    Private Sub fConsecutivo_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If Me.DsGlobal.GLO_CONSECUTIVO.GetChanges() IsNot Nothing Then
                GLO_CONSECUTIVOBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    GLO_CONSECUTIVOBindingNavigatorSaveItem.PerformClick()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub


    Private Sub fConsecutivo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim daSedes As New lbGlobalcom.dsGlobalTableAdapters.GLO_SEDESTableAdapter
            daSedes.Fill(DsGlobal.GLO_SEDES)
            daClave = New lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class